package com.sdses.weather.config.moji;

import com.sdses.weather.config.exception.BusinessException;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Component
@ConfigurationProperties(prefix = "weather.wind-direction")
@Data
public class WindDirectionConfig {

    /**
     * 按厂商配置风向映射
     */
    private Map<String, ProviderConfig> providers = new HashMap<>();

    @Data
    public static class ProviderConfig {
        private String type; // abbreviation | code | chinese-short | angle
        private Map<String, String> mapping = new LinkedHashMap<>();
    }

    /**
     * 获取指定厂商的配置，fallback 到 default
     */
    public ProviderConfig getProviderConfig(String provider) {
        ProviderConfig providerConfig = providers.get(provider);
        if (providerConfig == null) {
            throw new BusinessException("不支持该厂商的转换器:" + provider);
        }
        return providerConfig;
    }
}